package com.hfh.other;

import org.junit.Test;

import java.io.*;
import java.util.Scanner;

public class PrintStreamDemo {
    @Test
    public void test5() throws IOException {
        InputStream is = new FileInputStream("file\\a.txt");
        System.setIn(is);
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            System.out.println(sc.next());
        }
    }

    @Test
    public void test4() throws IOException {
//        Scanner sc = new Scanner(System.in);
        Scanner sc = new Scanner(new FileInputStream("file\\a.txt"));
        String str;
        while (sc.hasNext()) {
            System.out.println(sc.next());
        }
    }

    @Test
    public void test3() throws IOException {
        PrintWriter ps = new PrintWriter(new FileOutputStream("file\\d.txt"));
        ps.print(1);
        ps.print(2);

        ps.close();
    }

    @Test
    public void test2() throws IOException {
        PrintStream ps = new PrintStream(new FileOutputStream("file\\c.txt"));
        System.setOut(ps);

        System.out.println("nihao");
        System.out.println("haha");

    }

    @Test
    public void test1() throws IOException {
        PrintStream ps = new PrintStream(new FileOutputStream("file\\c.txt"));
        ps.println(1);
        ps.println(true);
        ps.println(2222222L);
        ps.flush();
        ps.close();
    }
}
